/*
@Time : 2019/8/20 0020 20:25
@Author : visons
*/
package main

import (
	"strings"
)

func TwoSum(nums []int, target int) []int {
	index := []int{0, 0}
	for i := 0; i < len(nums)-1; i++ {
		index[0] = i
		for j := i + 1; j < len(nums); j++ {
			if nums[i]+nums[j] == target {
				index[1] = j
				goto end
			}
		}
	}
end:
	return index
}

//
func LengthOfLongestSubstring(s string) int {
	maxLength := 0
	chars := strings.Split(s, "")
	leftIndex := 0
	for j := 0; j < len(chars); j++ {
		for innerIndex := leftIndex; innerIndex < j; innerIndex++ {
			if chars[innerIndex] == chars[j] {
				maxLength = Max(maxLength, j-leftIndex)
				leftIndex = innerIndex + 1
				break
			}
		}
	}
	return Max(len(chars)-leftIndex, maxLength)
}

func Max(a, j int) int {
	if a > j {
		return a
	} else {
		return j
	}
}
